#pragma once

#include <string>

namespace auth
{
  struct IAuthSession;

  struct IAuthEnvironment
  {
    virtual ~IAuthEnvironment() {}

    virtual IAuthSession *createSession() = 0;
  };

  struct IAuthSession
  {
    virtual ~IAuthSession() {}

    virtual bool isOpen() const = 0;
    virtual void open() = 0;
    virtual void close() = 0;

    virtual bool lock(const std::string& username, int *ret = NULL) = 0;
    virtual bool check(const std::string& username, const std::string& passcode, int *ret = NULL) = 0;
    virtual bool next(const std::string& passcode, int *ret = NULL) = 0;

    virtual bool setPIN(const std::string& pin, int *ret = NULL) = 0;
  };

  class CAuthException : public std::runtime_error  
  {
    int m_code;
  public:
    CAuthException(int code, const char *msg) 
      : std::runtime_error(msg), m_code(code)
    {
    }

    int getErrorCode(void) const
    {
      return m_code;
    }

    const char *getErrorMessage(void) const
    {
      return what();
    }
  };
} // namespace auth